package br.com.doclayer.fs;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import org.apache.commons.io.FileUtils;

import br.com.doclayer.ContentMetadata;
import br.com.doclayer.utils.DocUtils;

/**
 * @author helder
 * @author glauco
 * 
 */
public class ContentFsImpl implements ContentMetadata {

  @Override
  public String toString() {
    return "ContentFsImpl [UUID=" + this.uuid + ", name=" + this.name
        + ", mimeType=" + this.mimeType + ", createdBy=" + this.createdBy
        + ", creationDate=" + this.creationDate + ", lastModifiedBy="
        + this.lastModifiedBy + ", lastModificationDate="
        + this.lastModificationDate + ", size=" + this.size + "]";
  }

  private String uuid;
  private String name;
  private String mimeType;
  private String createdBy;
  private Date creationDate;
  private String lastModifiedBy;
  private Date lastModificationDate;
  private long size;

  public ContentFsImpl(File file, String uuid) throws IOException {
    if (!file.exists()) {
      throw new IllegalArgumentException("O arquivo informado não existe.");
    }
    if (!file.isFile()) {
      throw new IllegalArgumentException("O objeto informado não é um arquivo.");
    }
    this.uuid = uuid;
    this.name = file.getName();
    this.mimeType = DocUtils.getContentType(file);
    // this.createdBy = file.getCreatedBy();
    this.creationDate = new Date(file.lastModified());
    // this.lastModifiedBy = file.getLastModifiedBy();
    this.lastModificationDate = new Date(file.lastModified());
    this.size = FileUtils.sizeOf(file);
  }

  @Override
  public String getUuid() {
    return this.uuid;
  }

  @Override
  public String getName() {
    return this.name;
  }

  @Override
  public String getCreatedBy() {
    return this.createdBy;
  }

  @Override
  public Date getCreationDate() {
    return this.creationDate;
  }

  @Override
  public String getLastModifiedBy() {
    return this.lastModifiedBy;
  }

  @Override
  public Date getLastModificationDate() {
    return this.lastModificationDate;
  }

  @Override
  public String getMimeType() {
    return this.mimeType;
  }

  @Override
  public long getSize() {
    return this.size;
  }

}
